#define _CRT_SECURE_NO_WARNINGS 1
#include"Sort.h"
#include<time.h>
void test_selectsort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,3,1,4,7,3,6,9,3 };
	int size = sizeof(arr) / sizeof(arr[0]);
	SelectSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_bubblesort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,3,1,4,7,3,6,9,3 };
	int size = sizeof(arr) / sizeof(arr[0]);
	BubbleSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_insertsort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,3,1,4,7,3,6,9,3};
	int size = sizeof(arr) / sizeof(arr[0]);
	InsertSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_shellsort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,3,1,4,7,3,6,9,3 };
	int size = sizeof(arr) / sizeof(arr[0]);
	ShellSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_heapsort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,1,4,7,3,6,9,3 };
	int size = sizeof(arr) / sizeof(arr[0]);
	HeapSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_quicksort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,1,4,7,3,6,9,3 };
	int size = sizeof(arr) / sizeof(arr[0]);
	QuickSort3(arr, 0,size-1);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_mergesort() {
	int arr[] = { 3,2,1,0 ,4,2,45,2,1,4,7,3,6,9,3,1,2,6,9,8,7,5,1,9,78,9,15,9874,65,489 };
	int size = sizeof(arr) / sizeof(arr[0]);
	MergeSort2(arr, 0, size - 1);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void test_countsort() {
	int arr[] = { -998,997,996,990};
	int size = sizeof(arr) / sizeof(arr[0]);
	CountSort(arr, size);
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
}
void TestOP()
{
	srand(time(0));
	const int N = 1000000;
	int* a1 = (int*)malloc(sizeof(int) * N);
	int* a2 = (int*)malloc(sizeof(int) * N);
	int* a3 = (int*)malloc(sizeof(int) * N);
	int* a4 = (int*)malloc(sizeof(int) * N);
	int* a5 = (int*)malloc(sizeof(int) * N);
	int* a6 = (int*)malloc(sizeof(int) * N);
	int* a7 = (int*)malloc(sizeof(int) * N);

	for (int i = 0; i < N; ++i)
	{
		assert(a1 && a2 && a3 && a4 && a5 && a6 && a7);
		a1[i] = rand();
		a2[i] = a1[i];
		a3[i] = a1[i];
		a4[i] = a1[i];
		a5[i] = a1[i];
		a6[i] = a1[i];
		a7[i] = a1[i];
	}

	int begin1 = clock();
	//InsertSort(a1, N);
	int end1 = clock();

	int begin2 = clock();
	//ShellSort(a2, N);
	int end2 = clock();

	int begin7 = clock();
	//BubbleSort(a7, N);
	int end7 = clock();

	int begin3 = clock();
	QuickSort3(a3, 0, N - 1);
	int end3 = clock();

	int begin4 = clock();
	MergeSort2(a4, 0, N - 1);
	int end4 = clock();

	int begin5 = clock();
	QuickSort1(a5, 0, N - 1);
	int end5 = clock();

	int begin6 = clock();
	QuickSort2(a6, 0, N - 1);
	int end6 = clock();

	printf("InsertSort:%d\n", end1 - begin1);
	printf("ShellSort:%d\n", end2 - begin2);
	printf("BublleSort:%d\n", end7 - begin7);

	printf("MergeSort:%d\n", end4 - begin4);
	printf("QuickSort1:%d\n", end5 - begin5);
	printf("QuickSort2:%d\n", end6 - begin6);
	printf("QuickSort3:%d\n", end3 - begin3);

	free(a1);
	free(a2);
	free(a3);
	free(a4);
	free(a5);
	free(a6);
	free(a7);
}

int main() {
	/*TestOP();*/
	test_quicksort();
	return 0;
}